<template>
    <el-container>
        <el-main>
            <el-row>
                <el-col :span="propsData.component ? 24 : 8">
                    <el-card class="box-card">
                        <el-form :model="modifyForm" status-icon :rules="rules" ref="modifyForm" label-width="100px"
                                 class="demo-ruleForm" style="padding-top: 18px;">
                            <el-form-item label="账号" prop="loginId">
                                <el-input v-model="applier.loginId" readonly></el-input>
                            </el-form-item>
                            <el-form-item label="姓名" prop="name">
                                <el-input v-model="modifyForm.creator_name" readonly></el-input>
                            </el-form-item>
                            <el-form-item label="公司" prop="org_name">
                                <el-input v-model="applier.org_name" readonly></el-input>
                            </el-form-item>
                            <el-form-item label="申请时间" prop="create_date">
                                <el-input type="datepicker" v-model="modifyForm.create_date" readonly></el-input>
                            </el-form-item>
                            <el-form-item label="审核" prop="dealed_state">
                                <el-select value-field-name="id" v-model="modifyForm.dealed_state" :disabled="modifyForm.state===1">
                                    <el-option v-for="(item,index) in stateOptions" :label="item.name"
                                               :key="index" :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item v-if="!propsData.component">
                                <el-button type="primary" @click="submitForm" v-show="modifyForm.state===0">提交</el-button>
                            </el-form-item>
                        </el-form>
                    </el-card>
                </el-col>
                <el-col :span="24" v-if="propsData.component" style="text-align: center; margin-top: 15px;">
                    <el-button type="primary" @click="submitForm" v-show="modifyForm.state===0">提交</el-button>
                    <el-button @click="back">关闭</el-button>
                </el-col>
            </el-row>
        </el-main>
    </el-container>
</template>

<script>
    import sysUserApi from "@common/api/system/sysUserApi";

    export default {
        name: "change_device_audit",
        props: {
            propsData: {
                type: Object,
                default () {
                    return {
                        component: false,
                    };
                },
            },
        },
        data () {
            return {
                paramsData: {},
                stateOptions: [
                    {"id": 1, "name": "通过"},
                    {"id": -1, "name": "拒绝"},
                ],
                sid: this.$route.query.work_sid,
                modifyForm: {},
                applier: {},
                rules: {
                    dealed_state: [{required: true, message: '请选择审核结果', trigger: 'blur'}],
                }
            };
        },
        watch: {
            propsData: {
                handler () {
                    this.init();
                },
                deep: true,
                immediate: true,
            },
        },
        mounted () {
            if (!this.propsData.component) {
                this.init();
            }
        },
        methods: {
            back () {
                this.$emit('event', 'closeDialog');
            },
            init () {
                let $this = this;
                if ($this.propsData.component) {
                    $this.paramsData = $.extend({}, $this.propsData);
                } else {
                    $this.paramsData = $.extend({}, $this.$route.query);
                }
                if ($this.$utils.isNotEmpty($this.paramsData.work_sid)) {
                    $this.queryMsg($this.paramsData.work_sid);
                }
            },
            queryMsg (sid) {
                let $this = this;
            },
            submitForm () {
                let $this = this;
                $this.$refs['modifyForm'].validate((valid) => {
                    if (valid) {
                        let subData = $.extend({}, $this.modifyForm);
                        subData.is_deal = 1;
                        subData.state = 1;
                    } else {
                        return false;
                    }
                });
            },
        },

    }
</script>

<style scoped>

</style>
